package com.stu.reflection.factory;
// 客户类
public class Main {
  public static void main(String[] args) {
    test1();
    test2();
    test3();
  }

  // 测试普通工厂模式
  public static void test1() {
    IMessage localMessage = SimpleFactory.getInstanceOfMessage("localMessage");
    localMessage.send();
    IMessage netMessage = SimpleFactory.getInstanceOfMessage("netMessage");
    netMessage.send();
    IAnimal cat = SimpleFactory.getInstanceOfAnimal("cat");
    cat.eat();
    IAnimal dog = SimpleFactory.getInstanceOfAnimal("dog");
    dog.eat();
  }

  // 测试反射工厂模式（解决缺点1）
  public static void test2() {
    IMessage localMessage = ReflectionFactory1.getInstanceOfMessage("com.stu.reflection.factory.LocalMessage");
    localMessage.send();
    IMessage netMessage = ReflectionFactory1.getInstanceOfMessage("com.stu.reflection.factory.NetMessage");
    netMessage.send();
    IAnimal cat = ReflectionFactory1.getInstanceOfAnimal("com.stu.reflection.factory.Cat");
    cat.eat();
    IAnimal dog = ReflectionFactory1.getInstanceOfAnimal("com.stu.reflection.factory.Dog");
    dog.eat();
  }

  // 测试反射工厂模式（解决缺点2）
  public static void test3() {
    IMessage localMessage = ReflectionFactory2.getInstance("com.stu.reflection.factory.LocalMessage", IMessage.class);
    localMessage.send();
    IMessage netMessage = ReflectionFactory2.getInstance("com.stu.reflection.factory.NetMessage", IMessage.class);
    netMessage.send();
    IAnimal cat = ReflectionFactory2.getInstance("com.stu.reflection.factory.Cat", IAnimal.class);
    cat.eat();
    IAnimal dog = ReflectionFactory2.getInstance("com.stu.reflection.factory.Dog", IAnimal.class);
    dog.eat();
  }
}
